<?php
/**
 * bmi 体重指数计算
 */
$this->title = 'My Yii Application';
$css = <<<CSS
.sl{width:50px;display: inline-block;padding:6px 5px}
.sm{display: inline-block;width:10rem}
#result{margin-top: 10px}
CSS;

$this->registerCss($css);

$js = <<<JS

function Calc() {
    var i = 0;
    var difference,
    jy;
	var Ht=document.querySelector('#c1').value;
	var Weight=document.querySelector('#c2').value;
	 
    if (!Ht) {
        warningStr = '请输入您的身高';
        alert(warningStr);
        return;
    }
    if (!Weight) {
        warningStr = '请输入您的体重';
        alert(warningStr);
        return;
    }
    difference = (Weight) / ((Ht) * (Ht)) * 10000;
    if (difference < 15) {
        jy = "您太瘦，应去做个体检，增加营养。";
        i = 1;
    }
    if (difference >= 15 && difference < 19) {
        jy = "您过度苗条，应增加营养和锻炼。";
        i = 2;
    }
    if (difference >= 19 && difference < 22) {
        jy = "恭喜！！您是标准身材,注意保持。";
        i = 3;
    }
    if (difference >= 22 && difference < 25) {
        jy = "您是健康体重,但已不苗条，小心。";
        i = 4;
    }
    if (difference >= 25 && difference < 30) {
        jy = "您超重了，应该立即减肥！";
        i = 5;
    }
    if (difference >= 30 && difference < 40) {
        jy = "您很胖，减肥已是您的头等大事！";
        i = 6;
    }
    if (difference >= 40 && difference < 900) {
        jy = "您非常胖，肥胖将危及您的健康！";
        i = 7;
    }
    if (difference >= 900) {
        jy = "您不会比青蛙矮,身高单位是(厘米)";
        i = 8;
    }

    var re = '<table ><tbody><tr><th>计算结果</th></tr><tr><td style="text-align:left">体重指数：' + difference + '<br />建议：<span class="red">' + jy + '</span></td></tr></tbody></table>';
    document.getElementById("result").innerHTML = re;
    return false;
}

$('#daydiff').on('click',Calc);

JS;
$this->registerJs($js);

?>

<div class="site-index">
    <div class="body-content">
        <h3>bmi 体重指数计算</div>
    <hr/>
    <form >
        <div class="form-group  text-center col-md-12">
            <div class="input-group  col-lg-4">
                <span class="input-group-addon">身高</span><input id="c1" type="number" class="form-control sm" placeholder="请输入身高"/><span
                    class="input-group-addon">厘米</span>
            </div>
        </div>
        <div class="form-group  text-center col-md-12">
            <div class="input-group col-lg-4">
                <span class="input-group-addon">体重</span><input id="c2" type="number" class="form-control" placeholder="请输入体重"/><span
                        class="input-group-addon">千克</span>
            </div>
        </div>



        <div class="col-lg-4 text-center" style="margin-top: 4px">
            <a id="daydiff" class="btn btn-primary col-lg-4 col-xs-6" style="float: initial !important;">
                <i class="icon-chevron-down icon-white"></i>计算</a>
        </div>
        <div class="col-xs-12 col-lg-12 col-md-12 text-center moreheight" id="result"
             style="height: 4rem;text-height:4rem"></div>
    </form>
<div class="help-block col-lg-10">
    <div class="tb">
        <dl class="tools-Box-dlList">
            <p>BMI指数（Body Mass Index）即身体质量指数，是与体内脂肪总量密切相关的指标，主要反映全身性超重和肥胖。由于BMI计算的是身体脂肪的比例，所以在测量身体因超重而面临心脏病、高血压等风险上，比单纯的以体重来认定，更具准确性。</p>
            <p>BMI是评估身高体重比例的参考指数。它的计算公式为：体重(kg)除以身高(m)的平方(BMI =公斤/m2)</p>
            <dt class="red mt10" style="margin-bottom:0">体重指数：</dt>
            <dd>19以下&nbsp;体重偏低</dd>
            <dd>19-25&nbsp;健康体重</dd>
            <dd>25-30&nbsp;超重</dd>
            <dd>30-39&nbsp;严重超重</dd>
            <dd>40及40以上&nbsp;极度超重</dd>
            <p> <span class="red">注意：</span>并非每个人都适用BMI，如果你属于以下情况，那么BMI指数对你不适用：1. 未满18岁；2. 是运动员；3. 正在做重量训练；4. 怀孕或哺乳中；5. 身体虚弱或久坐不动的老人。</p>
        </dl>
    </div>

</div>

</div>



